<?php
/**
 *      [迷你云] (C)2009-2012 南京恒为网络科技.
 *   软件仅供研究与学习使用，如需商用，请访问www.miniyun.cn获得授权
 * 
 */
?>
<?php



class UserMeta extends CMiniyunModel
{
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

    public function tableName()
    {
        return Yii::app()->params['tablePrefix'].'user_metas';
    }

    
    public function getUserBaseMate($ids){
        if($ids=="") return array();
        return $this->findAll(array('condition'=>"user_id in(".$ids.") and meta_key in('email','avatar','nick','is_admin','phone','space')"));
    }

    
    public function  deleteUserMeta($userIds){
        if($userIds!='' && strlen($userIds)>0){
            $this->deleteAll("user_id in(".$userIds.")");
        }
    }

    
    public function isLastAdmin($userIds){
        return $this->count("meta_key='is_admin' and meta_value='1' and user_id not in(".$userIds.")")==0?true:false;
    }


    

    
    public function relations()
    {
                        return array(
                );
    }

    
    public function attributeLabels()
    {
        return array(
            'id' => 'ID',
            'user_id' => 'User',
            'meta_key' => '信息',
            'meta_value' => '信息',
            'created_at' => 'Created At',
            'updated_at' => 'Updated At',
        );
    }

    
    public function search()
    {
                
        $criteria=new CDbCriteria;

        $criteria->compare('id',$this->id);
        $criteria->compare('user_id',$this->user_id);
        $criteria->compare('meta_key',$this->meta_key,true);
        $criteria->compare('meta_value',$this->meta_value,true);
        $criteria->compare('created_at',$this->created_at,true);
        $criteria->compare('updated_at',$this->updated_at,true);

        return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
        ));
    }
}